
from PySide6.QtWidgets import QHBoxLayout, QVBoxLayout, QLayout, QWidget


def new_hbox(*args, p=None, stretch=0):
    box = QHBoxLayout(p)
    return _handle_box(box, *args, stretch)


def new_vbox(*args, p=None, stretch=0):
    box = QVBoxLayout(p)
    return _handle_box(box, *args, stretch)


def _handle_box(box, *args, stretch=0):
    if args:
        for arg in args:
            if isinstance(arg, QLayout):
                box.addLayout(arg, stretch)
            if isinstance(arg, QWidget):
                box.addWidget(arg, stretch)
    return box
